/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    device_timer.c
 *  @brief   Designware timer device adapter layer
 *  @version v1.0
 *  @date    03. Apr. 2023
 *  @author  liuchao
 ****************************************************************/

#include "irq.h"
#include "mem_map_table.h"
#include "crg.h"
#include "device_timer.h"

#if (USE_DW_TIMER_0)
static DEV_TIMER dw_timer_0;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_0;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_0;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_0(void)
{
	return dw_timer_open(&dw_timer_0);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_0(void)
{
	return dw_timer_close(&dw_timer_0);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_0(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_0, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_0(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_0, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_0(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_0, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_0(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_0, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_0(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_0;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_0.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_0);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_0_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = TIMER0_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER0);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_0;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_0;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_0;
	dw_timer_ptr->timer_close = dw_timer_close_0;
	dw_timer_ptr->timer_control = dw_timer_control_0;
	dw_timer_ptr->timer_write = dw_timer_write_0;
	dw_timer_ptr->timer_read = dw_timer_read_0;
}
#endif /* USE_DW_TIMER_0 */

#if (USE_DW_TIMER_1)
static DEV_TIMER dw_timer_1;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_1;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_1;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_1(void)
{
	return dw_timer_open(&dw_timer_1);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_1(void)
{
	return dw_timer_close(&dw_timer_1);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_1(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_1, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_1(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_1, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_1(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_1, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_1(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_1, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_1(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_1;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_1.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_1);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_1_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = TIMER1_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER1);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_1;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_1;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_1;
	dw_timer_ptr->timer_close = dw_timer_close_1;
	dw_timer_ptr->timer_control = dw_timer_control_1;
	dw_timer_ptr->timer_write = dw_timer_write_1;
	dw_timer_ptr->timer_read = dw_timer_read_1;
}
#endif /* USE_DW_TIMER_1 */

#if (USE_DW_TIMER_2)
static DEV_TIMER dw_timer_2;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_2;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_2;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_2(void)
{
	return dw_timer_open(&dw_timer_2);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_2(void)
{
	return dw_timer_close(&dw_timer_2);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_2(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_2, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_2(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_2, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_2(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_2, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_2(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_2, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_2(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_2;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_2.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_2);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_2_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = TIMER2_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER2);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_2;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_2;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_2;
	dw_timer_ptr->timer_close = dw_timer_close_2;
	dw_timer_ptr->timer_control = dw_timer_control_2;
	dw_timer_ptr->timer_write = dw_timer_write_2;
	dw_timer_ptr->timer_read = dw_timer_read_2;
}
#endif /* USE_DW_TIMER_2 */

#if (USE_DW_TIMER_3)
static DEV_TIMER dw_timer_3;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_3;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_3;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_3(void)
{
	return dw_timer_open(&dw_timer_3);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_3(void)
{
	return dw_timer_close(&dw_timer_3);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_3(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_3, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_3(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_3, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_3(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_3, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_3(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_3, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_3(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_3;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_3.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_3);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_3_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = TIMER3_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER3);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_3;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_3;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_3;
	dw_timer_ptr->timer_close = dw_timer_close_3;
	dw_timer_ptr->timer_control = dw_timer_control_3;
	dw_timer_ptr->timer_write = dw_timer_write_3;
	dw_timer_ptr->timer_read = dw_timer_read_3;
}
#endif /* USE_DW_TIMER_3 */

#if (USE_DW_TIMER_4)
static DEV_TIMER dw_timer_4;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_4;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_4;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_4(void)
{
	return dw_timer_open(&dw_timer_4);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_4(void)
{
	return dw_timer_close(&dw_timer_4);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_4(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_4, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_4(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_4, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_4(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_4, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_4(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_4, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_4(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_4;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_4.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_4);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_4_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = TIMER4_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER4);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_4;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_4;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_4;
	dw_timer_ptr->timer_close = dw_timer_close_4;
	dw_timer_ptr->timer_control = dw_timer_control_4;
	dw_timer_ptr->timer_write = dw_timer_write_4;
	dw_timer_ptr->timer_read = dw_timer_read_4;
}
#endif /* USE_DW_TIMER_4 */

#if (USE_DW_TIMER_5)
static DEV_TIMER dw_timer_5;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_5;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_5;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_5(void)
{
	return dw_timer_open(&dw_timer_5);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_5(void)
{
	return dw_timer_close(&dw_timer_5);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_5(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_5, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_5(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_5, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_5(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_5, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_5(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_5, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_5(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_5;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_5.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_5);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_5_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = TIMER5_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER5);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_5;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_5;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_5;
	dw_timer_ptr->timer_close = dw_timer_close_5;
	dw_timer_ptr->timer_control = dw_timer_control_5;
	dw_timer_ptr->timer_write = dw_timer_write_5;
	dw_timer_ptr->timer_read = dw_timer_read_5;
}
#endif /* USE_DW_TIMER_5 */

#if (USE_DW_TIMER_6)
static DEV_TIMER dw_timer_6;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_6;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_6;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_6(void)
{
	return dw_timer_open(&dw_timer_6);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_6(void)
{
	return dw_timer_close(&dw_timer_6);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_6(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_6, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_6(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_6, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_6(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_6, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_6(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_6, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_6(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_6;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_6.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_6);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_6_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = MAXIMUM_CLIC_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER6);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_6;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_6;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_6;
	dw_timer_ptr->timer_close = dw_timer_close_6;
	dw_timer_ptr->timer_control = dw_timer_control_6;
	dw_timer_ptr->timer_write = dw_timer_write_6;
	dw_timer_ptr->timer_read = dw_timer_read_6;
}
#endif /* USE_DW_TIMER_6 */

#if (USE_DW_TIMER_7)
static DEV_TIMER dw_timer_7;            /*!< designware timer object */
static DW_TIMER_CTRL dw_timer_ctrl_7;   /*!< designware timer ctrl */
static DEV_TIMER_MODE dw_timer_mode_7;  /*!< designware timer mode */

/** DesignWare TIMER open */
static int32_t dw_timer_open_7(void)
{
	return dw_timer_open(&dw_timer_7);
}

/** DesignWare TIMER  close */
static int32_t dw_timer_close_7(void)
{
	return dw_timer_close(&dw_timer_7);
}

/** DesignWare TIMER  control */
static int32_t dw_timer_control_7(uint32_t cmd, void *param)
{
	return dw_timer_control(&dw_timer_7, cmd, param);
}

/** DesignWare TIMER  write */
static int32_t dw_timer_write_7(uint32_t mode, uint32_t freq, uint32_t dc)
{
	return dw_timer_write(&dw_timer_7, mode, freq, dc);
}

/** DesignWare TIMER  read */
static int32_t dw_timer_read_7(uint32_t *mode, uint32_t *freq, uint32_t *dc)
{
	return dw_timer_read(&dw_timer_7, mode, freq, dc);
}

/** DesignWare TIMER  interrupt routine */
static void dw_timer_isr_7(void *ptr)
{
	dw_timer_isr_handler(&dw_timer_7, ptr);
}

/** Install DesignWare TIMER  to system */
static void dw_timer_install_7(void)
{
	DEV_TIMER *dw_timer_ptr = &dw_timer_7;
	DEV_TIMER_INFO *dw_timer_info_ptr = &(dw_timer_7.timer_info);
	DW_TIMER_CTRL_PTR dw_timer_ctrl_ptr = &(dw_timer_ctrl_7);

	/* Info init */
	dw_timer_info_ptr->timer_ctrl = (void *)dw_timer_ctrl_ptr;
	dw_timer_info_ptr->opn_cnt = 0;

	dw_timer_ctrl_ptr->id = DW_TIMER_7_ID;
	dw_timer_ctrl_ptr->regs = (DW_TIMER_REG_PTR)(MEM_MAP_TIMER_BASE_ADDR);
	dw_timer_ctrl_ptr->intno = MAXIMUM_CLIC_IRQn;
	dw_timer_ctrl_ptr->clock = get_mod_clk_rate(CRG_MOD_TIMER7);
	dw_timer_ctrl_ptr->int_handler = dw_timer_isr_7;
	dw_timer_ctrl_ptr->mode = dw_timer_mode_7;

	/** TIMER dev init */
	dw_timer_ptr->timer_open = dw_timer_open_7;
	dw_timer_ptr->timer_close = dw_timer_close_7;
	dw_timer_ptr->timer_control = dw_timer_control_7;
	dw_timer_ptr->timer_write = dw_timer_write_7;
	dw_timer_ptr->timer_read = dw_timer_read_7;
}
#endif /* USE_DW_TIMER_7 */

/**
 * @brief	install all timer objects
 * @note	@b MUST be called during system init
 */
void dw_timer_all_install(void)
{
#if (USE_DW_TIMER_0)
	dw_timer_install_0();
#endif
#if (USE_DW_TIMER_1)
	dw_timer_install_1();
#endif
#if (USE_DW_TIMER_2)
	dw_timer_install_2();
#endif
#if (USE_DW_TIMER_3)
	dw_timer_install_3();
#endif
#if (USE_DW_TIMER_4)
	dw_timer_install_4();
#endif
#if (USE_DW_TIMER_5)
	dw_timer_install_5();
#endif
#if (USE_DW_TIMER_6)
	dw_timer_install_6();
#endif
#if (USE_DW_TIMER_7)
	dw_timer_install_7();
#endif
}

/** get one designware device structure */
DEV_TIMER_PTR timer_get_dev(int32_t timer_id)
{
	static uint32_t install_flag = 0;

	/* intall device objects */
	if (install_flag == 0) {
		install_flag = 1;
		dw_timer_all_install();
	}

	switch (timer_id) {
#if (USE_DW_TIMER_0)
		case DW_TIMER_0_ID:
			return &dw_timer_0;
#endif
#if (USE_DW_TIMER_1)
		case DW_TIMER_1_ID:
			return &dw_timer_1;
#endif
#if (USE_DW_TIMER_2)
		case DW_TIMER_2_ID:
			return &dw_timer_2;
#endif
#if (USE_DW_TIMER_3)
		case DW_TIMER_3_ID:
			return &dw_timer_3;
#endif
#if (USE_DW_TIMER_4)
		case DW_TIMER_4_ID:
			return &dw_timer_4;
#endif
#if (USE_DW_TIMER_5)
		case DW_TIMER_5_ID:
			return &dw_timer_5;
#endif
#if (USE_DW_TIMER_6)
		case DW_TIMER_6_ID:
			return &dw_timer_6;
#endif
#if (USE_DW_TIMER_7)
		case DW_TIMER_7_ID:
			return &dw_timer_7;
#endif
		default:
			break;
	}

	return NULL;
}
